package org.cqut.system.work_record.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.cqut.system.work_record.domain.WorkRecord;
import org.cqut.system.work_record.service.WorkRecordService;
import org.cqut.system.work_record.mapper.WorkRecordMapper;
import org.cqut.system.work_record.vo.StudentWorkRecordVo;
import org.cqut.system.work_record.vo.TeacherWorkRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author XiAoXu
 */
@Service
public class WorkRecordServiceImpl extends ServiceImpl<WorkRecordMapper, WorkRecord>
        implements WorkRecordService {
    @Autowired
    private WorkRecordMapper workRecordMapper;

    @Override
    public List<TeacherWorkRecordVo> getRecordListForTeacher(String courseId) {
        return workRecordMapper.selectRecordListForTeacher(courseId);
    }

    @Override
    public boolean saveRecords(Map<Object, Object> map) {
        List<Integer> userIds = (List<Integer>) map.get("userIds");
        Integer contentId = (Integer) map.get("contentId");
        Integer courseId = Integer.valueOf((String) map.get("courseId"));
        int affected = 0;
        for (Integer userId : userIds) {
            WorkRecord workRecord = new WorkRecord();
            workRecord.setUserId(userId + "");
            workRecord.setContentId(contentId);
            workRecord.setCourseId(courseId);
            affected += workRecordMapper.insert(workRecord);
        }
        return affected == userIds.size();
    }

    @Override
    public List<StudentWorkRecordVo> getRecordListForStudent(String studentId, String courseId) {
        return workRecordMapper.selectRecordListForStudent(studentId,courseId);
    }

    @Override
    public String getWorkPath(String recordId) {
        return workRecordMapper.selectWorkPath(recordId);
    }
}




